//
//  Ext+UIBarButton.swift
//  TMDWeiBo
//
//  Created by 汤明鼎 on 2017/1/17.
//  Copyright © 2017年 heimaitcast. All rights reserved.
//

import UIKit

extension UIBarButtonItem{

    convenience init(imageNamed:String?=nil,title:String?=nil,target:Any?=nil,action:Selector) {
        self.init()
        let btn = UIButton()
        
        btn.addTarget(target, action: action, for: UIControlEvents.touchUpInside)
        
        if let img = imageNamed {
            btn.setImage(UIImage(named:img), for: UIControlState.normal)
            btn.setImage(UIImage(named:"\(img)_highlighted"), for: UIControlState.highlighted)
        }
        
        if let tit = title {
            btn.setTitle(tit, for: UIControlState.normal)
            btn.setTitleColor(UIColor.darkGray, for: UIControlState.normal)
            btn.setTitleColor(TMDMainColor, for: UIControlState.highlighted)
            btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        }
        
        btn.sizeToFit()
        customView = btn
    }




}
